<style lang="less">
  @import '../../styles/common.less';
</style>

<template>
<div style="width: 480px; margin-top: 20px;">
  <Form ref="person" :model="person" :rules="ruleValidate" :label-width="110">
    <FormItem label="姓名" prop="name">
      <Input v-model="person.name" placeholder="请输入姓名"></Input>
    </FormItem>
    <FormItem label="性别" prop="sex">
      <Input v-model="person.sex" placeholder="请输入性别"></Input>
    </FormItem>
    <FormItem label="身份证" prop="idcard">
      <Input v-model="person.idcard" placeholder="请输入身份证"></Input>
    </FormItem>
    <FormItem label="手机号" prop="telephone">
      <Input v-model="person.telephone" placeholder="请输入手机号"></Input>
    </FormItem>
    <FormItem label="学号" prop="number">
      <Input v-model="person.number" placeholder="请输入学号"></Input>
    </FormItem>
    <FormItem label="班级">
      <Input v-model="person.class" disabled="true"></Input>
    </FormItem>
    <FormItem label="班主任">
      <Input v-model="person.classPerson" disabled="true"></Input>
    </FormItem>
    <FormItem label="班级类型">
      <Input v-model="person.classType" disabled="true"></Input>
    </FormItem>
    <FormItem label="班级描述">
      <Input v-model="person.classDesc" disabled="true"></Input>
    </FormItem>
    <FormItem label="班级文件">
      <a v-for="item in person.files" :src="item.url"></a>
    </FormItem>
    <FormItem label="班级描述">
      <Input v-model="person.remark" disabled="true"></Input>
    </FormItem>

    <FormItem>
      <Button type="primary" @click="handleSubmit('person')">保存</Button>
    </FormItem>
  </Form>
</div>
</template>

<script>
  import Cookies from 'js-cookie';
    export default {
        name: "personinfo",
        data(){
          return{
            person:{
              id:'',
              name:'',
              sex:'',
              idcard:'',
              telephone:'',
              number:'',
              class:'',
              classPerson:'',
              classType:'',
              classDesc:'',
              files:[],
              college:'',
              remark:''
            },
            ruleValidate:{
              name:[
                {required: true,message:'请输入姓名',trigger:'blur'}
              ],
              sex:[
                {required: true,message:'请输入性别',trigger:'blur'}
              ],
              idcard:[
                {required: true,message:'请输入身份证',trigger:'blur'}
              ],
              telephone:[
                {required: true,message:'请输入手机号码',trigger:'blur'}
              ],
              number:[
                {required: true,message:'请输入学号',trigger:'blur'}
              ],
              class:[
                {required: true,message:'请输入班级',trigger:'blur'}
              ],
              remark:[
                {required: true,message:'请输入备注',trigger:'blur'}
              ],

            },
            uploadList: []
          }
        },
        methods:{
          handleSubmit(name){
            this.$refs[name].validate((valid) => {
              if (valid) {
                let dataArr = {
                  id:this.person.id,
                  stduentName:this.person.name,
                  stduentNo:this.person.number,
                  stduentSex:this.person.sex,
                  stduentPhone:this.person.telephone,
                  stduentIdCard:this.person.idcard,
                  stduentClass:this.person.class,
                  stduentCollege:this.person.college
                };

                this.$http.post('/school/updStdInfo',dataArr).then(res =>{
                  this.$Message.success('更新成功!');
                });
              }
            })
          }
        },
      mounted(){
        this.$http.get('/school/getStdInfo?phone='+Cookies.get('user')).then(res =>{
          var dt = res.data.data;
          this.person.id = dt.id;
          this.person.name = dt.stduentName;
          this.person.sex = dt.stduentSex;
          this.person.idcard = dt.stduentIdCard;
          this.person.telephone = dt.stduentPhone;
          this.person.number = dt.stduentNo;
          this.person.class = dt.stduentClass;
          this.person.college = dt.stduentCollege;
          this.person.classPerson = dt.classPerson;
          this.person.classType = dt.classType;
          this.person.classDesc = dt.classDesc;
          this.person.remark = dt.remark;
          if(dt.files != '' && dt.files != undefined){
            var files = dt.files.split(',');
            for(var i in files){
              var p = {"url":files[i]}
              this.person.files.put(p);
            }
          }
        });
      }
    }
</script>

<style scoped>

</style>
